<?php
if(!empty($_POST) AND !isset($_POST['Entry'])){}
$build = RequestData('buildings');
$ressi = RequestData('resource');
$i = 0;
foreach($build as $value)
{
	if($value > 0) ++$i;
}
?>
<form method="POST">
	<table class="buildings" style="table-layout: fixed; width: 720px;">
		<colgroup>
			<col style="width:115px;">
			<col style="width:auto;">
			<col style="width:100px">
		</colgroup>
		<thead>
			<td>Geb&auml;ude</td>
		</thead>
		<?php
			$con = Connect();
			$check = mysql_query("SELECT * FROM buildings_build");
			if($i-1 == 9)
			{
				while($building = mysql_fetch_object($check))
				{
					if($build[$building->Name] > 0)
					{
						$lock = array(false, false, false);
						echo '<tr><th><img src="../Game/template/Images/buildings/'.$building->Name.'.png"></th>';
						echo '<th><p>'.$building->Name.'['.$build[$building->Name].']</p><p>'.$building->Description.'</p>';
						echo '<p>Zeit: '.$building->Time.'</p><p>Ben&ouml;tigte Ressourcen: ';
						if(!($ressi['Credits'] >= $building->Credits))
						{
							echo '<p><b style="color:#FF0000;">'.$building->Credits.' Credits</b>, '; 
							$lock[0] = true;
						}else{
							echo '<p><b style="color:#00FF00;">'.$building->Credits.' Credits</b>, '; 
						}
						if(!($ressi['Titan'] >= $building->Titan))
						{
							echo '<b style="color:#FF0000;">'.$building->Titan.' Titan</b>, '; 
							$lock[1] = true;
						}else{
							echo '<b style="color:#00FF00;">'.$building->Titan.' Titan</b>, '; 
						}
						if(!($ressi['Oel'] >= $building->Oel))
						{
							echo '<b style="color:#FF0000;">'.$building->Oel.' &Ouml;l</b></p>'; 
							$lock[2] = true;
						}else{
							echo '<b style="color:#00FF00;">'.$building->Oel.' &Ouml;l</b></p>'; 
						}
						echo '</th><th><p><input class="button" type="submit" name="'.$building->Name.'" value="Stufe '.++$build[$building->Name].'" style="width:80px;" ';
						if($lock[0] == true || $lock[1] == true || $lock[2] == true) echo 'disabled';
						echo '></p></th></tr>';
					}
				}
			}else{
				while($building = mysql_fetch_object($check))
				{
					$lock = array(false, false, false);
					echo '<tr><th><img src="../Game/template/Images/buildings/'.$building->Name.'.png"></th>';
					echo '<th><p>'.$building->Name.'['.$build[$building->Name].']</p><p>'.$building->Description.'</p>';
					echo '<p>Zeit: '.$building->Time.'</p><p>Ben&ouml;tigte Ressourcen: ';
					if(!($ressi['Credits'] >= $building->Credits))
					{
						echo '<p><b style="color:#FF0000;">'.$building->Credits.' Credits</b>, '; 
						$lock[0] = true;
					}else{
						echo '<p><b style="color:#00FF00;">'.$building->Credits.' Credits</b>, '; 
					}
					if(!($ressi['Titan'] >= $building->Titan))
					{
						echo '<b style="color:#FF0000;">'.$building->Titan.' Titan</b>, '; 
						$lock[1] = true;
					}else{
						echo '<b style="color:#00FF00;">'.$building->Titan.' Titan</b>, '; 
					}
					if(!($ressi['Oel'] >= $building->Oel))
					{
						echo '<b style="color:#FF0000;">'.$building->Oel.' &Ouml;l</b></p>'; 
						$lock[2] = true;
					}else{
						echo '<b style="color:#00FF00;">'.$building->Oel.' &Ouml;l</b></p>'; 
					}
					echo '</th><th><p><input class="button" type="submit" name="'.$building->Name.'" value="Stufe '.++$build[$building->Name].'" style="width:80px;" ';
					if($lock[0] == true || $lock[1] == true || $lock[2] == true) echo 'disabled';
					echo '></p></th></tr>';
				}
			}
			Close($con);
		?>
	</table>
</form>